package com.bawei.http

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import javax.inject.Singleton

/**
 * 使用Hilt模块封装Http请求实例
 */
@Module
@InstallIn(SingletonComponent::class)
object HttpHiltModule {

    /**
     * 提供OkHttpClient单例
     */
    @HttpClientAnnotation
    @Provides
    @Singleton
    fun provideOkHttpClient(): OkHttpClient {
        return OkHttpClientManager.createOkHttpClient()
    }

    /**
     * 提供OkHttpsClient单例
     */
    @HttpsClientAnnotation
    @Provides
    @Singleton
    fun provideOkHttpsClient(): OkHttpClient {
        return OkHttpClientManager.createOkHttpsClient()
    }

    /**
     * 提供HttpRetrofit单例
     */
    @HttpRetrofitAnnotation
    @Provides
    @Singleton
    fun provideHttpRetrofit(@HttpClientAnnotation okHttpClient: OkHttpClient): Retrofit {
        return OkHttpClientManager.createRetrofit(okHttpClient)
    }

    /**
     * 提供HttpsRetrofit单例
     */
    @HttpsRetrofitAnnotation
    @Provides
    @Singleton
    fun provideHttpsRetrofit(@HttpsClientAnnotation okHttpsClient: OkHttpClient): Retrofit {
        return OkHttpClientManager.createRetrofit(okHttpsClient)
    }

}